package com.yangfan.thread.thread_wangwenjun04;

import java.util.Collection;

/**
 * @description: 自定义 Lock 接口
 * @author: yangfan
 * @date: Created in 2020/1/27 0027 17:18
 * @modified By:
 *
 */
public interface Lock {


    void lock() throws InterruptedException;

    //尝试去获取锁，如果指定毫秒内没有获取到 则放弃
    void lock(long mills) throws InterruptedException, TimeOutException;

    //释放锁
    void unlock();

    //获取被锁住的线程
    Collection<Thread> getBlockedThread();

    //获取被锁住的线程的数量
    int getBlockedSize();


    /**
     * 自定义异常类
     */
    class TimeOutException extends Exception {

        public TimeOutException(String message) {
            super(message);
        }

    }


}